/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-12 10:20:14
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-15 22:41:20
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/components/animation_text.dart';
import 'package:flutter_data_center/components/custom_tile.dart';
import 'package:flutter_data_center/controller/home_controller.dart';
import 'package:flutter_data_center/model/home/school_moment_model.dart';
import 'package:get/get.dart';

import '../../../../constants.dart';

class SchoolData extends StatelessWidget {
  const SchoolData({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) => GetBuilder<HomeController>(
        builder: (_controller) => Column(
          children: [
            CustomTile(title: "校园姿态", tap: () {}),
            SizedBox(height: 20),
            _controller.momentList.length > 0
                ? Container(
                    padding: EdgeInsets.symmetric(vertical: 12),
                    margin: EdgeInsets.symmetric(horizontal: 5),
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(defaultRadius),
                      boxShadow: [
                        BoxShadow(
                          offset: Offset(0, 0),
                          blurRadius: 5,
                          spreadRadius: 1,
                          color: Color.fromRGBO(0, 0, 0, 0.08),
                        ),
                      ],
                    ),
                    child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          ..._controller.momentList.map((e) => buildItem(e)),
                        ]),
                  )
                : Center(child: CircularProgressIndicator()),
          ],
        ),
      );

  Expanded buildItem(SchoolMomentModel item) {
    return Expanded(
      child: Container(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Row(
              crossAxisAlignment: CrossAxisAlignment.end,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                AnimText(
                  number: item.count,
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 24,
                    fontWeight: FontWeight.w500,
                  ),
                ),
                SizedBox(width: 8),
                Text(item.unit,
                    style: TextStyle(
                      color: Color(0xff9c9c9c),
                      fontSize: 13,
                      height: 3,
                    )),
              ],
            ),
            Text(
              item.title,
              style: TextStyle(
                fontSize: 14,
              ),
            )
          ],
        ),
      ),
    );
  }
}
